package cn.edu.tyu.finance.thingstype.dao;

import cn.edu.tyu.finance.thingstype.domain.Users;
import cn.edu.tyu.util.DbUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UserDaoImpl {
    public int addUser(Users users) throws SQLException {
        Connection conn = DbUtil.getConnection();

        String sql = "insert into users values(?,?,?)";

        PreparedStatement ps = conn.prepareStatement(sql);

        ps.setString(1,users.getUseid());
        ps.setString(2,users.getUsename());
        ps.setString(1,users.getUserpsw());

        int res = ps.executeUpdate();

        DbUtil.backConn(conn,ps,null);
        return res;
    }

    public static void main(String[] args) throws SQLException {
        UserDaoImpl userDao = new UserDaoImpl();
        Users users = new Users();
        users.setUseid("1");
        users.setUsename("yhx");
        users.setUserpsw("123456");
        int res = userDao.addUser(users);
        System.out.println("res="+res);
    }
}
